<script setup>
import hospitalapi from '../api'
import { ref ,computed} from 'vue';



const data = ref([])
async function GetCount(){

 let result  = await hospitalapi.get("/api/getDep_idCount")
 data.value=result.data;
  console.log("44444444444444"+data.value)
}
   
GetCount();
const computedData = computed(() => {
  return data.value ? transformData(data.value) : [];
});

function transformData(data) {
  return data.map(item => ({
    value: item.count, // 确保 count 存在
    
    name: item.department.name // 使用 departmentName 作为名称
  }));
}

const option =ref({
    title: {
    text: '住院人员分布情况',
    subtext: '实时记录',
    left: 'center'
  },
  tooltip: {
    trigger: 'item'
  },
  legend: {
    orient: 'vertical',
    left: 'left'
  },
  series:  computed(() => [
    {
      name: '科室',
      type: 'pie',
      radius: '50%',
      data: computedData.value,
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
  ])

})

</script>
<template>
<e-charts class="chart" :option="option" />

</template>
<style>
.chart{
    height: 600px
}
</style>
